<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../static/bootstrap.min.css">
    <script src="../static/jquery.min.js"></script>
    <script src="../static/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../layuiadmin/layui/css/layui.css">
</head>
<body>
<ul class="breadcrumb">
    <li>修改密码</li>
</ul>
<form role="form" style="width: 45%;margin-left: 8%;" enctype="multipart/form-data">
    <div class="alert alert-danger" style="display: none;">两次密码不一致!!!</div>
    <label >修改密码</label>
    <input type="password" class="form-control" name="changepassword" placeholder="修改密码">
    <label >确定密码</label>
    <input type="password" class="form-control" name="determinepassword" placeholder="确定密码">
</form>
<div style="margin-top: 20px;margin-left: 8%;">
    <button id="reset" type="button" class="btn btn-default">重置</button>
    <button id="confirmChange" type="button" class="btn btn-primary">确定修改</button>
</div>
<script src="../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../layuiadmin/' //静态资源所在路径
    }).extend({
        index: '/lib/index' //主入口模块
    }).use(['index', 'table'], function(){
        $(function(){
            $("#reset").click(function(){
                $("[name=changepassword]").val("");
                $("[name=determinepassword]").val("");
            });
            $("#confirmChange").click(function(){
                if($("[name=changepassword]").val()!=
                    $("[name=determinepassword]").val()){
                    $(".alert-danger").show();
                    /**显示3s消失
                     * */
                    setTimeout(function(){
                        $(".alert-danger").hide();
                    },5000);
                }else if($("input[name=changepassword]").val()==""||$("input[name=determinepassword]").val()==""){
                    layer.msg("修改密码不能为空!!!");
                }else {
                    $.ajax({
                        url:"/MS/changepassword",
                        data:{id:getQueryVariable("data"),
                        password:$("input[name=changepassword]").val()},
                        success:function(response){
                            if(response>0){
                                layer.msg("修改密码成功，请重新登录");
                                setTimeout(function(){
                                    window.top.location.reload();
                                    $.ajax({
                                        url:"/MS/signout"
                                    });
                                    window.top.location.href="../index.html";
                                },1000);
                            }else if(response==-2){
                                layer.msg("与原密码一致，请重新更改密码!!!");
                            }else{
                                layer.msg("修改密码失败，请重新尝试");
                            }
                        }
                    });
                }
            });
        });
        function getQueryVariable(variable) {
            let query = window.top.location.search.substring(1);
            let vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                let pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }
    });
</script>
</body>
</html>